<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java中的 == 与 equals() 深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
        }
        
        .content-card {
            background: white;
            border-radius: 16px;
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 25px 30px -5px rgba(0, 0, 0, 0.15), 0 15px 15px -5px rgba(0, 0, 0, 0.06);
        }
        
        .code-block {
            background: #1e293b;
            color: #e2e8f0;
            border-radius: 12px;
            padding: 1.5rem;
            overflow-x: auto;
            position: relative;
            margin: 1.5rem 0;
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 0.5rem;
            right: 0.5rem;
            background: #475569;
            color: #cbd5e1;
            padding: 0.25rem 0.75rem;
            border-radius: 6px;
            font-size: 0.75rem;
            font-weight: 500;
        }
        
        .section-title {
            position: relative;
            padding-left: 1rem;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 100%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f3e7e9 0%, #e3eeff 99%, #e3eeff 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            border-radius: 8px;
            margin: 1.5rem 0;
        }
        
        .comparison-table {
            background: white;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
        
        .comparison-table th {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 1rem;
            text-align: left;
            font-weight: 600;
        }
        
        .comparison-table td {
            padding: 1rem;
            border-bottom: 1px solid #e5e7eb;
        }
        
        .comparison-table tr:hover {
            background: #f9fafb;
        }
        
        .icon-feature {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.5rem;
            margin-bottom: 1rem;
        }
        
        .mermaid {
            margin: 2rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.25rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 relative">
        <div class="container mx-auto px-6 relative z-10">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                    <i class="fas fa-code mr-4"></i>== vs equals()
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">深入理解 Java 中的对象比较机制</p>
                <div class="flex justify-center space-x-4">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-clock mr-2"></i>阅读时间：10分钟
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-layer-group mr-2"></i>深度解析
                    </span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="content-card p-8 mb-8">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>Java编程中，<code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">==</code> 和 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">equals()</code> 是比较对象或基本类型的两种常用方式。它们看似相似，实则在用途和实现上有着显著的区别。理解这两者的差异，是每个Java开发者必须掌握的基础知识。
            </p>
        </div>

        <!-- Comparison Overview -->
        <div class="grid md:grid-cols-2 gap-8 mb-12">
            <div class="content-card p-8">
                <div class="icon-feature">
                    <i class="fas fa-equals"></i>
                </div>
                <h2 class="text-2xl font-bold mb-4 text-gray-800">== 运算符</h2>
                <p class="text-gray-600 mb-4">比较运算符，用于比较两个操作数是否相等</p>
                <ul class="space-y-2 text-gray-700">
                    <li><i class="fas fa-check-circle text-green-500 mr-2"></i>基本类型：比较值</li>
                    <li><i class="fas fa-check-circle text-green-500 mr-2"></i>引用类型：比较内存地址</li>
                    <li><i class="fas fa-check-circle text-green-500 mr-2"></i>性能更高</li>
                </ul>
            </div>
            
            <div class="content-card p-8">
                <div class="icon-feature">
                    <i class="fas fa-code-branch"></i>
                </div>
                <h2 class="text-2xl font-bold mb-4 text-gray-800">equals() 方法</h2>
                <p class="text-gray-600 mb-4">Object类的方法，用于比较对象内容是否相等</p>
                <ul class="space-y-2 text-gray-700">
                    <li><i class="fas fa-check-circle text-green-500 mr-2"></i>可被重写</li>
                    <li><i class="fas fa-check-circle text-green-500 mr-2"></i>比较对象内容</li>
                    <li><i class="fas fa-check-circle text-green-500 mr-2"></i>更灵活的比较逻辑</li>
                </ul>
            </div>
        </div>

        <!-- Detailed Explanation -->
        <div class="content-card p-8 mb-8">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">1. == 运算符详解</h2>
            
            <p class="text-gray-700 mb-6 leading-relaxed">
                <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">==</code> 是一个比较运算符，其行为根据操作数的类型不同而有所区别：
            </p>

            <div class="mb-8">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-cube text-purple-600 mr-2"></i>基本数据类型
                </h3>
                <p class="text-gray-700 mb-4">
                    对于基本数据类型（如 <code class="bg-gray-100 text-gray-800 px-2 py-1 rounded">int</code>、<code class="bg-gray-100 text-gray-800 px-2 py-1 rounded">char</code>、<code class="bg-gray-100 text-gray-800 px-2 py-1 rounded">boolean</code> 等），<code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">==</code> 比较的是值是否相等。
                </p>
                <div class="code-block">
                    <pre><code>int a = 5;
int b = 5;
System.out.println(a == b);  // 输出 true</code></pre>
                </div>
            </div>

            <div>
                <h3 class="text-xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-link text-purple-600 mr-2"></i>引用类型
                </h3>
                <p class="text-gray-700 mb-4">
                    对于引用类型（如对象），<code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">==</code> 比较的是两个对象的引用是否相同，也就是它们在内存中是否指向同一个对象。
                </p>
                <div class="code-block">
                    <pre><code>String str1 = new String("Hello");
String str2 = new String("Hello");
System.out.println(str1 == str2);  // 输出 false</code></pre>
                </div>
                <div class="highlight-box">
                    <p class="text-gray-700">
                        <i class="fas fa-info-circle text-blue-600 mr-2"></i>
                        虽然 <code class="bg-gray-100 text-gray-800 px-2 py-1 rounded">str1</code> 和 <code class="bg-gray-100 text-gray-800 px-2 py-1 rounded">str2</code> 内容相同，但它们是两个不同的对象，存储在不同的内存位置，因此 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">==</code> 返回 <code class="bg-gray-100 text-gray-800 px-2 py-1 rounded">false</code>。
                    </p>
                </div>
            </div>
        </div>

        <!-- equals() Method Explanation -->
        <div class="content-card p-8 mb-8">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">2. equals() 方法详解</h2>
            
            <p class="text-gray-700 mb-6 leading-relaxed">
                <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">equals()</code> 是 <code class="bg-gray-100 text-gray-800 px-2 py-1 rounded">Object</code> 类的方法，用于比较两个对象的内容是否相等。
            </p>

            <div class="mb-8">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-cog text-purple-600 mr-2"></i>默认行为
                </h3>
                <p class="text-gray-700 mb-4">
                    <code class="bg-gray-100 text-gray-800 px